package com.employeemanage.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.employeemanage.domain.bean.TblProductOrder;
import com.employeemanage.service.TblProductOrderService;
import com.employeemanage.mapper.TblProductOrderMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.employeemanage.domain.vo.ProductOrderVO;
import java.util.List;

/**
* @author 郭可欣
* @description 针对表【tbl_product_order(商品销售订单)】的数据库操作Service实现
* @createDate 2025-07-05 14:20:29
*/
@Service
@Transactional
public class TblProductOrderServiceImpl extends ServiceImpl<TblProductOrderMapper, TblProductOrder>
    implements TblProductOrderService{

    @Override
    public List<ProductOrderVO> getOrderVOList(String orderType, String customerName, String employeeName) {
        return baseMapper.selectOrderVOList(orderType, customerName, employeeName);
    }

    @Override
    public ProductOrderVO getOrderDetail(Long id) {
        TblProductOrder order = this.getById(id);
        if (order == null) return null;
        // 这里只做简单映射，实际可查客户、员工名
        ProductOrderVO vo = new ProductOrderVO();
        vo.setId(order.getId());
        vo.setOrderType(order.getOrderType());
        vo.setTotalAmount(order.getTotalAmount());
        vo.setPaymentMethod(order.getPaymentMethod() == null ? null : order.getPaymentMethod().toString());
        vo.setQuantity(order.getQuantity());
        vo.setCreatedAt(order.getCreatedAt());
        // TODO: 关联查客户、员工名
        return vo;
    }

    @Override
    public void addOrder(TblProductOrder order) {
        if (order.getStatus() == null) {
            order.setStatus("已完成");
        }
        this.save(order);
    }

    @Override
    public void updateOrder(TblProductOrder order) {
        this.updateById(order);
    }

    @Override
    public void deleteOrder(Long id) {
        this.removeById(id);
    }
}




